import itertools

numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

# 提取小于等于5的连续元素
taken_numbers = itertools.takewhile(lambda x: x <= 5, numbers)

for number in taken_numbers:
    print(number)